package com.qf3.web;

import com.alibaba.druid.pool.DruidDataSource;
import com.qf3.dao.UserDao;
import com.qf3.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserServlet {
    public static void main(String[] args) {

        ApplicationContext ioc = new ClassPathXmlApplicationContext("spring-ioc.xml");
//        UserService userService = (UserService) ioc.getBean("userServiceImpl");
//        UserDao userDao = (UserDao) ioc.getBean("userDao");
//
//        System.out.println(userService);
//        System.out.println(userDao);

        //根据类型获取对应类型的对象（前提：这种类型的对象在spring容器中只能有一个）
        UserService userService = ioc.getBean(UserService.class);
        System.out.println(userService);
        UserDao userDao = ioc.getBean(UserDao.class);
        System.out.println(userDao);

        System.out.println("-----------------");
        DruidDataSource ds = (DruidDataSource) ioc.getBean("getDs");
        System.out.println(ds);
    }
}
